package no.ntnu.fp.net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class ClientTCP {
	Socket socket;
	BufferedReader in;
	PrintWriter out;
	
	public ClientTCP(){
		
		try {
			socket = new Socket(InetAddress.getLocalHost(), 4001);
			in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			out = new PrintWriter(socket.getOutputStream());
		} 
		catch (UnknownHostException e) {} 
		catch (IOException e) {}
	}
	
	public void send(String message) {
		
		out.print(message);
	}
	
	public String receive() {
		
		try {
			return in.readLine();
		} 
		catch (IOException e) {}
		
		return null;
	}
	
	public void close() {
		
		out.close();
		try {
			in.close();
		} 
		catch (IOException e) {}
		
		
	}
	
	
}
